#include <pthread.h>
#include <iostream>
#include <string>
#include <unistd.h>

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void* wake(void* arg)
{
    std::string name = static_cast<char*>(arg);
    while(true)
    {
        sleep(1);
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond,&mutex);
        std::cout<<"我是"<<name<<std::endl;
        pthread_mutex_unlock(&mutex);
    }
}

int main()
{
    pthread_t t1,t2;
    pthread_create(&t1,NULL,wake,(void*)"线程A");
    pthread_create(&t2,NULL,wake,(void*)"线程B");

    while(true)
    {
        pthread_cond_broadcast(&cond);
    }
    return 0;   
}